import threading
from concurrent.futures import ThreadPoolExecutor, wait
from typing import Generator, Any

from DrissionPage._base.chromium import Chromium
from DrissionPage._configs.chromium_options import ChromiumOptions
from DrissionPage._pages.chromium_tab import ChromiumTab

from util.crawler_util import random_sleep_thread

community_room_executor = ThreadPoolExecutor(max_workers=20, thread_name_prefix='test')
co = ChromiumOptions()
co.auto_port()
b = Chromium(addr_or_opts=co)
def do():
    with threading.Lock():
        tab = b.new_tab()
    random_sleep_thread(None,20, 40)
    tab.get('https://www.baidu.com')
    tab.wait(10)
    tab.close()
# tab.reconnect()


futures = [community_room_executor.submit(do) for i in range(1000)]
wait(futures)
